/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.compomics.xtandemparser.xmlreader.operations.parser.handler;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 *
 * @author Kenneth
 */
public class PeptideHandler extends DefaultHandler {

    boolean isPeptide = false;
    StringBuilder sequence = new StringBuilder();

    public String getSequence() {
        return sequence.toString();
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes)
            throws SAXException {
        if (qName.equalsIgnoreCase("peptide")) {
            System.out.println("From :" + attributes.getValue("start") + " to " + attributes.getValue("end"));
            isPeptide = true;
        }
    }

    @Override
    public void characters(char ch[], int start, int length) throws SAXException {
        if (isPeptide) {
            sequence.append(new String(ch, start, length));
        }
    }

    @Override
    public void endElement(String uri, String localName, String qName)
            throws SAXException {
        isPeptide = false;
    }
}
